package at.fhooe.stefanirndorfer.game;

import java.io.FileNotFoundException;

import org.lwjgl.LWJGLException;

import at.fhooe.stefanirndorfer.dynamicchange.DynamicChangeHandler;
import at.fhooe.stefanirndorfer.entity.EntityManager;
import at.fhooe.stefanirndorfer.event.EventManager;
import at.fhooe.stefanirndorfer.event.QueuedDispatchStrategy;
import at.fhooe.stefanirndorfer.event.SaveListenerStrategy;
import at.fhooe.stefanirndorfer.graphics.RenderManager;
import at.fhooe.stefanirndorfer.graphics.Window;
import at.fhooe.stefanirndorfer.input.InputManager;
import at.fhooe.stefanirndorfer.labeling.Labeling_Manager;
import at.fhooe.stefanirndorfer.labeling.Region_Manager;
import at.fhooe.stefanirndorfer.quadtree.QuadTree_Manager;
import at.fhooe.stefanirndorfer.resources.ResLoader;
import at.fhooe.stefanirndorfer.timer.Timer;



public class Game {

	private static int W_WIDTH = 1024;
	private static int W_HEIGHT = 768;
	
	private static Game instance = null;
	
	private Window window;
	private Timer timer;
	private RenderManager render_manager;
	private InputManager input_manager;
	private EntityManager entity_manager;
	private EventManager event_manager;
	private ResLoader resource_loader;
	private QuadTree_Manager quad_tree_manager;
	private Labeling_Manager labeling_manager;
	private DynamicChangeHandler dynamic_change_handler;
	private Region_Manager region_manager;
	
	


	private Game() throws LWJGLException, FileNotFoundException {
		timer = new Timer();
		input_manager = new InputManager(W_WIDTH, W_HEIGHT);
		render_manager = new RenderManager();
		entity_manager = new EntityManager();
		resource_loader = new ResLoader();
		event_manager = new EventManager(new QueuedDispatchStrategy(), new SaveListenerStrategy());
		quad_tree_manager = new QuadTree_Manager();
		labeling_manager = new Labeling_Manager();
		dynamic_change_handler = new DynamicChangeHandler(labeling_manager, quad_tree_manager, event_manager);
		region_manager = new Region_Manager();
		window = new Window(W_WIDTH, W_HEIGHT, "Dynamic-Change-Demo",this);
		
	}

	
	public static Game getInstance() {
		if (instance == null) {
			try {
				instance = new Game();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (LWJGLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("Hallo, die Game-Instanz wurde erstellt");
		}
		return instance;
	}
	
	
	public void invokeGameLoop(){
		try {
			try {
				window.openWindow();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (LWJGLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	///////////////////////////////////////////////////////////////////////
	///// GETTERS AND SETTERS
	///////////////////////////////////////////////////////////////////////
	
	
	
	public Region_Manager getRegionManager(){
		return region_manager;
	}
	
	public DynamicChangeHandler getDynamic_change_handler() {
		return dynamic_change_handler;
	}


	public void setDynamic_change_handler(
			DynamicChangeHandler dynamic_change_handler) {
		this.dynamic_change_handler = dynamic_change_handler;
	}


	public void setRegionManager(Region_Manager rm){
		this.region_manager = rm;
	}
	
	public Window getWindow() {
		return window;
	}

	public QuadTree_Manager getQuadTreeManager() {
		return quad_tree_manager;
	}


	public void setQuadTreeManager(QuadTree_Manager quad_tree_manager) {
		this.quad_tree_manager = quad_tree_manager;
	}


	public Labeling_Manager getLabelingManager() {
		return labeling_manager;
	}


	public void setLabelingManager(Labeling_Manager labeling_manager) {
		this.labeling_manager = labeling_manager;
	}


	public ResLoader getResource_loader() {
		return resource_loader;
	}


	public void setResource_loader(ResLoader resource_loader) {
		this.resource_loader = resource_loader;
	}


	public EventManager getEvent_manager() {
		return event_manager;
	}


	public void setEvent_manager(EventManager event_manager) {
		this.event_manager = event_manager;
	}


	public void setWindow(Window window) {
		this.window = window;
	}


	public RenderManager getRenderManager() {
		return render_manager;
	}

	public void setRenderManager(RenderManager render_manager) {
		this.render_manager = render_manager;
	}



	public InputManager getInputManager() {
		return input_manager;
	}


	public EntityManager getEntityManager() {
		return entity_manager;
	}
	
	public Timer getTimer(){
		return timer;
	}


}
